package com.yyx.server.config;

import com.yyx.server.vo.ResultVo;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLException;
import java.sql.SQLIntegrityConstraintViolationException;

/**
 * 全局异常处理
 * @author YongXin
 * @date Created in 2021/7/31 16:33
 */
@RestControllerAdvice
public class GlobalException {
    @ExceptionHandler(SQLException.class)
    public ResultVo sqlExceptin(SQLException sqlException){
        if (sqlException instanceof SQLIntegrityConstraintViolationException){
            return ResultVo.error("该数据有关联数据，操作失败！");
        }
        System.out.println(sqlException);
        return ResultVo.error("数据库异常，操作失败！");
    }
}
